package leetcode.code0680;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public boolean validPalindrome(String s) {
		char[] cs = s.toCharArray();
		return validPalindrome(cs, 0, s.length() - 1);
	}

	private boolean validPalindrome(char[] cs, int l, int r) {
		while (l <= r) {
			if (cs[l] != cs[r]) {
				if (this.validPalind(cs, l + 1, r) || this.validPalind(cs, l, r - 1)) {
					return true;
				} else {
					return false;
				}
			}
			l++;
			r--;
		}
		return true;
	}

	private boolean validPalind(char[] cs, int l, int r) {
		while (l <= r) {
			if (cs[l] != cs[r]) {
				return false;
			}
			l++;
			r--;
		}
		return true;
	}

	@Override
	public void debug4() {
		HelpDebug.compare(true, this.validPalindrome("aba"));
		HelpDebug.compare(true, this.validPalindrome("abca"));
		HelpDebug.compare(false, this.validPalindrome("abc"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();


	}

}
